<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>opencv | 一个不知道名字的博客</title><meta name="author" content="戎老大"><meta name="copyright" content="戎老大"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="opencv学习笔记上传  1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969">
<meta property="og:type" content="article">
<meta property="og:title" content="opencv">
<meta property="og:url" content="http://example.com/2023/03/22/opencv/index.html">
<meta property="og:site_name" content="一个不知道名字的博客">
<meta property="og:description" content="opencv学习笔记上传  1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/img/rong_blog_cover.jpg">
<meta property="article:published_time" content="2023-03-22T15:29:56.000Z">
<meta property="article:modified_time" content="2023-04-06T06:38:33.780Z">
<meta property="article:author" content="戎老大">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/img/rong_blog_cover.jpg"><link rel="shortcut icon" href="https://rong-1315651883.cos.ap-beijing.myqcloud.com/rong-1315651883/0.webp"><link rel="canonical" href="http://example.com/2023/03/22/opencv/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'opencv',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-06 14:38:33'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = url => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      link.onload = () => resolve()
      link.onerror = () => reject()
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.zhimg.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.min.css" media="print" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><div class="loading-img"></div><div class="loading-image-dot"></div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><link rel="stylesheet" href="/css/progress_bar.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://rong-1315651883.cos.ap-beijing.myqcloud.com/rong-1315651883/dog.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/rong_blog_cover.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="一个不知道名字的博客"><span class="site-name">一个不知道名字的博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">opencv</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-22T15:29:56.000Z" title="发表于 2023-03-22 23:29:56">2023-03-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-06T06:38:33.780Z" title="更新于 2023-04-06 14:38:33">2023-04-06</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span id="" data-flag-title="opencv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="twikoo_visitors"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><center>

<h1 id="opencv学习笔记上传"><a href="#opencv学习笔记上传" class="headerlink" title="opencv学习笔记上传"></a>opencv学习笔记上传</h1></center>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br><span class="line">658</span><br><span class="line">659</span><br><span class="line">660</span><br><span class="line">661</span><br><span class="line">662</span><br><span class="line">663</span><br><span class="line">664</span><br><span class="line">665</span><br><span class="line">666</span><br><span class="line">667</span><br><span class="line">668</span><br><span class="line">669</span><br><span class="line">670</span><br><span class="line">671</span><br><span class="line">672</span><br><span class="line">673</span><br><span class="line">674</span><br><span class="line">675</span><br><span class="line">676</span><br><span class="line">677</span><br><span class="line">678</span><br><span class="line">679</span><br><span class="line">680</span><br><span class="line">681</span><br><span class="line">682</span><br><span class="line">683</span><br><span class="line">684</span><br><span class="line">685</span><br><span class="line">686</span><br><span class="line">687</span><br><span class="line">688</span><br><span class="line">689</span><br><span class="line">690</span><br><span class="line">691</span><br><span class="line">692</span><br><span class="line">693</span><br><span class="line">694</span><br><span class="line">695</span><br><span class="line">696</span><br><span class="line">697</span><br><span class="line">698</span><br><span class="line">699</span><br><span class="line">700</span><br><span class="line">701</span><br><span class="line">702</span><br><span class="line">703</span><br><span class="line">704</span><br><span class="line">705</span><br><span class="line">706</span><br><span class="line">707</span><br><span class="line">708</span><br><span class="line">709</span><br><span class="line">710</span><br><span class="line">711</span><br><span class="line">712</span><br><span class="line">713</span><br><span class="line">714</span><br><span class="line">715</span><br><span class="line">716</span><br><span class="line">717</span><br><span class="line">718</span><br><span class="line">719</span><br><span class="line">720</span><br><span class="line">721</span><br><span class="line">722</span><br><span class="line">723</span><br><span class="line">724</span><br><span class="line">725</span><br><span class="line">726</span><br><span class="line">727</span><br><span class="line">728</span><br><span class="line">729</span><br><span class="line">730</span><br><span class="line">731</span><br><span class="line">732</span><br><span class="line">733</span><br><span class="line">734</span><br><span class="line">735</span><br><span class="line">736</span><br><span class="line">737</span><br><span class="line">738</span><br><span class="line">739</span><br><span class="line">740</span><br><span class="line">741</span><br><span class="line">742</span><br><span class="line">743</span><br><span class="line">744</span><br><span class="line">745</span><br><span class="line">746</span><br><span class="line">747</span><br><span class="line">748</span><br><span class="line">749</span><br><span class="line">750</span><br><span class="line">751</span><br><span class="line">752</span><br><span class="line">753</span><br><span class="line">754</span><br><span class="line">755</span><br><span class="line">756</span><br><span class="line">757</span><br><span class="line">758</span><br><span class="line">759</span><br><span class="line">760</span><br><span class="line">761</span><br><span class="line">762</span><br><span class="line">763</span><br><span class="line">764</span><br><span class="line">765</span><br><span class="line">766</span><br><span class="line">767</span><br><span class="line">768</span><br><span class="line">769</span><br><span class="line">770</span><br><span class="line">771</span><br><span class="line">772</span><br><span class="line">773</span><br><span class="line">774</span><br><span class="line">775</span><br><span class="line">776</span><br><span class="line">777</span><br><span class="line">778</span><br><span class="line">779</span><br><span class="line">780</span><br><span class="line">781</span><br><span class="line">782</span><br><span class="line">783</span><br><span class="line">784</span><br><span class="line">785</span><br><span class="line">786</span><br><span class="line">787</span><br><span class="line">788</span><br><span class="line">789</span><br><span class="line">790</span><br><span class="line">791</span><br><span class="line">792</span><br><span class="line">793</span><br><span class="line">794</span><br><span class="line">795</span><br><span class="line">796</span><br><span class="line">797</span><br><span class="line">798</span><br><span class="line">799</span><br><span class="line">800</span><br><span class="line">801</span><br><span class="line">802</span><br><span class="line">803</span><br><span class="line">804</span><br><span class="line">805</span><br><span class="line">806</span><br><span class="line">807</span><br><span class="line">808</span><br><span class="line">809</span><br><span class="line">810</span><br><span class="line">811</span><br><span class="line">812</span><br><span class="line">813</span><br><span class="line">814</span><br><span class="line">815</span><br><span class="line">816</span><br><span class="line">817</span><br><span class="line">818</span><br><span class="line">819</span><br><span class="line">820</span><br><span class="line">821</span><br><span class="line">822</span><br><span class="line">823</span><br><span class="line">824</span><br><span class="line">825</span><br><span class="line">826</span><br><span class="line">827</span><br><span class="line">828</span><br><span class="line">829</span><br><span class="line">830</span><br><span class="line">831</span><br><span class="line">832</span><br><span class="line">833</span><br><span class="line">834</span><br><span class="line">835</span><br><span class="line">836</span><br><span class="line">837</span><br><span class="line">838</span><br><span class="line">839</span><br><span class="line">840</span><br><span class="line">841</span><br><span class="line">842</span><br><span class="line">843</span><br><span class="line">844</span><br><span class="line">845</span><br><span class="line">846</span><br><span class="line">847</span><br><span class="line">848</span><br><span class="line">849</span><br><span class="line">850</span><br><span class="line">851</span><br><span class="line">852</span><br><span class="line">853</span><br><span class="line">854</span><br><span class="line">855</span><br><span class="line">856</span><br><span class="line">857</span><br><span class="line">858</span><br><span class="line">859</span><br><span class="line">860</span><br><span class="line">861</span><br><span class="line">862</span><br><span class="line">863</span><br><span class="line">864</span><br><span class="line">865</span><br><span class="line">866</span><br><span class="line">867</span><br><span class="line">868</span><br><span class="line">869</span><br><span class="line">870</span><br><span class="line">871</span><br><span class="line">872</span><br><span class="line">873</span><br><span class="line">874</span><br><span class="line">875</span><br><span class="line">876</span><br><span class="line">877</span><br><span class="line">878</span><br><span class="line">879</span><br><span class="line">880</span><br><span class="line">881</span><br><span class="line">882</span><br><span class="line">883</span><br><span class="line">884</span><br><span class="line">885</span><br><span class="line">886</span><br><span class="line">887</span><br><span class="line">888</span><br><span class="line">889</span><br><span class="line">890</span><br><span class="line">891</span><br><span class="line">892</span><br><span class="line">893</span><br><span class="line">894</span><br><span class="line">895</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># *创建与显示窗口</span></span><br><span class="line"><span class="comment"># namedWindow(name,flag)</span></span><br><span class="line"><span class="comment"># imshow(name,flag)</span></span><br><span class="line"><span class="comment"># destroyALLWindows()</span></span><br><span class="line"><span class="comment"># resizeWindow(name,width,height)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;new&#x27;,0)</span></span><br><span class="line"><span class="string">cv2.resizeWindow(&#x27;new&#x27;,1920,1080)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">key = cv2.waitKey(0)</span></span><br><span class="line"><span class="string">if key == &#x27;q&#x27; :</span></span><br><span class="line"><span class="string">    exit()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *打开文件,并显示</span></span><br><span class="line"><span class="comment"># imread()</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">img = cv2.imread(&#x27;./0.webp&#x27;,)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;new&#x27;,img)</span></span><br><span class="line"><span class="string">if cv2.waitKey(0) &amp; 0xff==ord(&#x27;q&#x27;):</span></span><br><span class="line"><span class="string">    cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *保存图片</span></span><br><span class="line"><span class="comment"># imwrite(name,img) </span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">img = cv2.imread(&#x27;./123.png&#x27;,)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;new&#x27;,img)</span></span><br><span class="line"><span class="string">if cv2.waitKey(0) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">    cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string">elif cv2.waitKey(0) &amp; 0xff==ord(&#x27;S&#x27;):</span></span><br><span class="line"><span class="string">    cv2.imwrite(&#x27;./1/123.jpg&#x27;,img)</span></span><br><span class="line"><span class="string">    print(&quot;已保存&quot;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *通过摄像头采集</span></span><br><span class="line"><span class="comment"># VideoCapture()</span></span><br><span class="line"><span class="comment"># cap.read()</span></span><br><span class="line"><span class="comment"># cap.release()</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 创建屏幕</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 获取视频设备</span></span><br><span class="line"><span class="string">cap = cv2.VideoCapture(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">while True:</span></span><br><span class="line"><span class="string">    ret,frame = cap.read()</span></span><br><span class="line"><span class="string">    cv2.imshow(&#x27;new&#x27;,frame)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    if cv2.waitKey(5) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">        break</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cap.release()</span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="comment"># *从多媒体读取视频帧</span></span><br><span class="line"><span class="comment"># VideoCapture(&quot;输入文件路径&quot;)</span></span><br><span class="line"><span class="comment"># cap.read()</span></span><br><span class="line"><span class="comment"># cap.release()</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *视频录制</span></span><br><span class="line"><span class="comment"># VideoWriter(name,格式Fourcc,帧率,分辨率)</span></span><br><span class="line"><span class="comment"># write()</span></span><br><span class="line"><span class="comment"># release()</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">fourcc = cv2.VideoWriter_fourcc(*&#x27;MJPG&#x27;)                </span></span><br><span class="line"><span class="string">vw = cv2.VideoWriter(&#x27;./123.mp4&#x27;,fourcc,25,(1280,720))   # !分辨率需要和摄像头分辨率相同</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 创建屏幕</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 申请摄像头</span></span><br><span class="line"><span class="string">cap = cv2.VideoCapture(0) </span></span><br><span class="line"><span class="string">if cap.isOpened() :     #判断是否打开摄像头</span></span><br><span class="line"><span class="string">    while True:</span></span><br><span class="line"><span class="string">        ret,frame = cap.read()</span></span><br><span class="line"><span class="string">        cv2.imshow(&#x27;new&#x27;,frame)</span></span><br><span class="line"><span class="string">        vw.write(frame)            </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        if cv2.waitKey(5) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">            break</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cap.release()</span></span><br><span class="line"><span class="string">vw.release()</span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *鼠标控制</span></span><br><span class="line"><span class="comment"># 鼠标设置回调函数setMouseCallback(windowname,callback,userdate)</span></span><br><span class="line"><span class="comment"># callback(event,x,y,flags,userdate) event --鼠标移动，按下... ||flags  --组合键</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">def mousecallback(event,x,y,flags,userdate):</span></span><br><span class="line"><span class="string">    print(event,x,y,flags,userdate)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.setMouseCallback(&#x27;new&#x27;,mousecallback,&quot;123&quot;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img = np.zeros((360,640,3),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">while True:</span></span><br><span class="line"><span class="string">    cv2.imshow(&#x27;new&#x27;,img)</span></span><br><span class="line"><span class="string">    if cv2.waitKey(5) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">            break</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *Trackbar控件</span></span><br><span class="line"><span class="comment"># createTrackbar(Trackbarname,winname,value:当前值,count:最大值,callback,userdate)</span></span><br><span class="line"><span class="comment"># getTrackBarPos(trackbarname,winname) return 当前值</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27; </span></span><br><span class="line"><span class="string">def callback():</span></span><br><span class="line"><span class="string">    pass</span></span><br><span class="line"><span class="string">#创建窗口</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;trackbar&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 创建trackbar  </span></span><br><span class="line"><span class="string">cv2.createTrackbar(&#x27;R&#x27;,&#x27;trackbar&#x27;,0,255,callback)</span></span><br><span class="line"><span class="string">cv2.createTrackbar(&#x27;G&#x27;,&#x27;trackbar&#x27;,0,255,callback)</span></span><br><span class="line"><span class="string">cv2.createTrackbar(&#x27;B&#x27;,&#x27;trackbar&#x27;,0,255,callback)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img = np.zeros((480,640,3),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">while True:</span></span><br><span class="line"><span class="string">    cv2.imshow(&#x27;trackbar&#x27;,img)</span></span><br><span class="line"><span class="string">    R = cv2.getTrackbarPos(&#x27;R&#x27;,&#x27;trackbar&#x27;)</span></span><br><span class="line"><span class="string">    G = cv2.getTrackbarPos(&#x27;G&#x27;,&#x27;trackbar&#x27;)</span></span><br><span class="line"><span class="string">    B = cv2.getTrackbarPos(&#x27;B&#x27;,&#x27;trackbar&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    img[:] = [B,G,R]</span></span><br><span class="line"><span class="string">    if cv2.waitKey(5) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">        break</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *OPENCV </span></span><br><span class="line"><span class="comment"># opencv --BGR</span></span><br><span class="line"><span class="comment"># HSV色相 饱和度 / HSB / HSL  </span></span><br><span class="line"><span class="comment"># YUV 视频</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ?HSV ：</span></span><br><span class="line"><span class="comment"># Hue              -色相，即色彩  </span></span><br><span class="line"><span class="comment"># Saturation       -饱和度，颜色的纯度</span></span><br><span class="line"><span class="comment"># Value            -明度</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ?YUV：</span></span><br><span class="line"><span class="comment"># Y 灰色图像</span></span><br><span class="line"><span class="comment"># UV 颜色</span></span><br><span class="line"><span class="comment"># YUV 4:2:0   4:2:2   4:4:4</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">def callback():</span></span><br><span class="line"><span class="string">    pass</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;color&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">img = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># cv2.imshow(&#x27;color&#x27;,img)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 颜色空间转化数组</span></span><br><span class="line"><span class="string">colorspaces = [cv2.COLOR_BGR2RGBA,</span></span><br><span class="line"><span class="string">               cv2.COLOR_BGR2GRAY,cv2.COLOR_BGR2HSV_FULL,</span></span><br><span class="line"><span class="string">               cv2.COLOR_BGR2YUV]</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.createTrackbar(&#x27;trackcolor&#x27;,&#x27;color&#x27;,0,len(colorspaces),callback)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">while True:</span></span><br><span class="line"><span class="string">    index = cv2.getTrackbarPos(&#x27;trackcolor&#x27;,&#x27;color&#x27;)</span></span><br><span class="line"><span class="string">    # 颜色空间转换api</span></span><br><span class="line"><span class="string">    img_cv = cv2.cvtColor(img,colorspaces[index])</span></span><br><span class="line"><span class="string">    cv2.imshow(&#x27;color&#x27;,img_cv)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    if cv2.waitKey(5) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">         break</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *Numpy</span></span><br><span class="line"><span class="comment"># Opencv用到的矩阵都要转换成Numpy数组</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建矩阵：</span></span><br><span class="line"><span class="comment">#     --array()           创建数组</span></span><br><span class="line"><span class="comment">#     --zeros()/ones      创建全0数组/全1</span></span><br><span class="line"><span class="comment">#     --full()            创建全值数组</span></span><br><span class="line"><span class="comment">#     --identity/eye()    创建单元数组</span></span><br><span class="line"><span class="comment"># 检索与赋值[y,x]</span></span><br><span class="line"><span class="comment"># 获得子数组[:,:]</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># !  创建数组</span></span><br><span class="line"><span class="comment"># # 创建数组array()</span></span><br><span class="line"><span class="comment"># a = np.array([1,2,3])</span></span><br><span class="line"><span class="comment"># b = np.array([[1,2],[3,4]])</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># # 创建数组zeros()</span></span><br><span class="line"><span class="comment"># c = np.zeros((480,640,3),np.uint8)        #((行的个数，列的个数，通道数/层数)，矩阵每一个元素的元素类型)     </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># # 创建数组ones()</span></span><br><span class="line"><span class="comment"># d = np.ones((8,8,3),np.uint8)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># # 创建数组full()</span></span><br><span class="line"><span class="comment"># e = np.full((8,8,3),255,np.uint8)                             #((行的个数，列的个数，通道数/层数)，每个元素的值，矩阵每一个元素的元素类型)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># # 创建数组identity()</span></span><br><span class="line"><span class="comment"># f = np.identity(3)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !  数组的检索与赋值</span></span><br><span class="line"><span class="comment"># [y,x,channel]   y在前 从0开始 channel 为二维矩阵的层数</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;imgshow&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img = np.zeros((480,640,3),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 向矩阵中某个元素赋值</span></span><br><span class="line"><span class="string">counter = 0</span></span><br><span class="line"><span class="string">while counter &lt;200:</span></span><br><span class="line"><span class="string">    img[counter,100,0] = 255</span></span><br><span class="line"><span class="string">    img[counter,200,1] = 255</span></span><br><span class="line"><span class="string">    img[counter,300,2] = 255</span></span><br><span class="line"><span class="string">    counter +=1 </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;imgshow&#x27;,img)</span></span><br><span class="line"><span class="string">if cv2.waitKey(0)&amp;0xff ==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">    cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="comment"># !获取子矩阵  (ROI) [y1:y2,x1,x2]   [:,:]</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;cv2.namedWindow(&#x27;imgshow&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img = np.zeros((480,640,3),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">sub = img[100:200,100:200]</span></span><br><span class="line"><span class="string">sub[:,:] = [0,0,255]</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;imgshow&#x27;,img)</span></span><br><span class="line"><span class="string">if cv2.waitKey(0)&amp;0xff ==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">    cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *opencv 的重要结构体Mat</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># dims -维度   rows.cols  -行列数      *data   -存放数据的指针      *refcount   引用记数</span></span><br><span class="line"><span class="comment">#Mat 的深拷贝和浅拷贝</span></span><br><span class="line"><span class="comment"># 默认浅拷贝，共用一块内存</span></span><br><span class="line"><span class="comment"># 深拷贝  copy()     </span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">img = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img2= img                              #浅拷贝</span></span><br><span class="line"><span class="string">img3 = img.copy()                      #深拷贝</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img[10:100,10:100] = [0,0,255]</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img&#x27;,img)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img2&#x27;,img2)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img3&#x27;,img3)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *访问Mat图像的属性</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">img = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">print(img.shape)            # (986, 1000, 3)(高度，宽度，通道数)</span></span><br><span class="line"><span class="string">print(img.size)             # 2958000       高度*长度*通道数</span></span><br><span class="line"><span class="string">print(img.dtype)            # uint8         0-255每个元素的位深</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *通道的分离与合并</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># split(mat)</span></span><br><span class="line"><span class="comment"># merge((ch1,ch2,ch3...))</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img = np.zeros((480,640,3),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">b,g,r=cv2.split(img)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">b[10:100,10:100] =255</span></span><br><span class="line"><span class="string">g[10:100,10:100] =255</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img2 = cv2.merge((b,g,r))</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;B&#x27;,b)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;g&#x27;,g)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img&#x27;,img)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img2&#x27;,img2)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *opencv 绘制图型</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !画直线</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">img = np.zeros((480,640,3),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">#line(img,起点，终点，颜色，线宽,线形（越大越平滑-1,4,8,16）)</span></span><br><span class="line"><span class="string">cv2.line(img,(10,20),(300,400),(0,0,255),5,16)      #!(x,y)  x在前</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img&#x27;,img)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !画椭圆</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"># ellipse(img,中心点，长宽的一半，角度，从哪个角度开始，从哪个角度结束...)</span></span><br><span class="line"><span class="string">cv2.ellipse(img ,(320,240),(100,50),0,0,360,(0,255,0),3,16)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *案例</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">img = np.zeros((480,640,3),np.uint8)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;mouse&#x27;,cv2.WINDOW_AUTOSIZE)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">def mousecallback(event,x,y,flags,userdate):</span></span><br><span class="line"><span class="string">    print(event,x,y,flags,userdate)</span></span><br><span class="line"><span class="string">    if flags == 1:</span></span><br><span class="line"><span class="string">         img[y,x] = 255</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.setMouseCallback(&#x27;mouse&#x27;,mousecallback,&quot;123&quot;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">while True:</span></span><br><span class="line"><span class="string">    cv2.imshow(&#x27;mouse&#x27;,img)</span></span><br><span class="line"><span class="string">    if cv2.waitKey(1) &amp; 0xff==ord(&#x27;Q&#x27;):</span></span><br><span class="line"><span class="string">            break</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *图像的加法运算</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">kunkun = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">#图的加法运算就是矩阵的加法运算</span></span><br><span class="line"><span class="string">print(kunkun.shape)</span></span><br><span class="line"><span class="string">img = np.ones((986,1000,3),np.uint8)  * 20</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kunkun2 = cv2.add(kunkun,img)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;img&#x27;,kunkun2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *图像的减法运算</span></span><br><span class="line"><span class="comment"># cat = cv2.imread(&#x27;./smallcat1.jpg&#x27;)</span></span><br><span class="line"><span class="comment"># back = cv2.imread(&#x27;./back.jpg&#x27;)</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># print(cat)</span></span><br><span class="line"><span class="comment"># print(back)</span></span><br><span class="line"><span class="comment">#图的加法运算就是矩阵的加法运算</span></span><br><span class="line"><span class="comment"># print(kunkun.shape)</span></span><br><span class="line"><span class="comment"># img = np.ones((986,1000,3),np.uint8)  * 150</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># kunkun2 = cv2.add(kunkun,img)               #加更亮</span></span><br><span class="line"><span class="comment"># cv2.imshow(&#x27;img&#x27;,kunkun2)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># kunkun3 = cv2.subtract(kunkun,img)          #减更暗</span></span><br><span class="line"><span class="comment"># cv2.imshow(&#x27;img2&#x27;,kunkun3) </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># kunkun4 = cv2.multiply(kunkun,2)          #乘法</span></span><br><span class="line"><span class="comment"># kunkun5 = cv2.divide(kunkun,2)            #除法</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#图像的融合  addWeighted(A,alpha,B,bate,gamma)           alapha 和   bate是占比权重     gamma 静态权</span></span><br><span class="line"><span class="comment"># img1=cv2.addWeighted(cat,0.2,back,0.8,0)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># cv2.imshow(&#x27;img2&#x27;,img1)</span></span><br><span class="line"><span class="comment"># cv2.waitKey(0)</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *图像的滤波</span></span><br><span class="line"><span class="comment"># !滤波器 -卷积核，滤波叫卷积</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 卷积核的大小 </span></span><br><span class="line"><span class="comment"># 3*3 5*5 7*7   卷积核越大，感受野越多，提取特征越好，同时计算量越大</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 卷积的锚点</span></span><br><span class="line"><span class="comment"># 正中心</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 边界扩充</span></span><br><span class="line"><span class="comment"># 如何卷积核大于1 且不进行边界扩充，则输出的图片尺寸减小</span></span><br><span class="line"><span class="comment"># 如果进行扩充，则相等</span></span><br><span class="line"><span class="comment">#    N    = (   W    -     F      +      2P   )/    S     + 1</span></span><br><span class="line"><span class="comment"># 输出图像 = 原图大小    卷积核大小      扩充尺寸   步长大小</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># filter2D(src(哪一个图像), ddepth(滤波后的位深/-1), kernel(卷积核), anchor(锚点/默认-1), dalta(每次卷积后加的值/ 默认0), borderTypr(边界的类型))</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># !低通滤波与高通滤波</span></span><br><span class="line"><span class="comment"># 低通滤波可以去除噪声或平滑图像</span></span><br><span class="line"><span class="comment"># 高通滤波可以查找图像边缘</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">kernel_5 = np.ones((5,5),np.float32) /25</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cat = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string">dit = cv2.filter2D(cat, -1, kernel_5)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;cat&#x27;,cat)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;dst&#x27;,dit)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># !方盒滤波与均值滤波</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 方盒滤波   boxFilter(src(哪一个图像), ddepth(滤波后的位深/-1), ksize(卷积核大小), anchor(锚点/默认-1), normalize(), borderTypr(边界的类型))</span></span><br><span class="line"><span class="comment"># normalize = true   a = 1/W * H    均值滤波</span></span><br><span class="line"><span class="comment">#           = False  a = 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># blur(src, ksize, anchor, borderType)</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cat = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">dit = cv2.blur(cat,(5,5))</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;cat&#x27;,cat)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;dst&#x27;,dit)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># *高斯滤波</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># GaussianBlur(img, kerel, sigmaX, sigmaY, ...)</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cat = cv2.imread(&#x27;./gaussian.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">dit = cv2.GaussianBlur(cat,(5,5),sigmaX=5)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;cat&#x27;,cat)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;dst&#x27;,dit)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *形态学</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 1.基于图像形态进行处理的一些基本方法</span></span><br><span class="line"><span class="comment"># 2.基于二进制的图像进行处理</span></span><br><span class="line"><span class="comment"># 3.卷积核决定图像处理后的效果</span></span><br><span class="line"><span class="comment"># ?腐蚀与膨胀（缩小和放大）</span></span><br><span class="line"><span class="comment"># 开运算 </span></span><br><span class="line"><span class="comment"># 闭运算 </span></span><br><span class="line"><span class="comment"># 顶帽</span></span><br><span class="line"><span class="comment"># 黑帽</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;math&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;math2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">kunkun = cv2.imread(&#x27;./math.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 转为灰度图</span></span><br><span class="line"><span class="string">kunkun2 = cv2.cvtColor(kunkun,cv2.COLOR_BGR2GRAY)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># !二值化</span></span><br><span class="line"><span class="string"># ret,dst = cv2.threshold(kunkun2, 180, 255, cv2.THRESH_BINARY)</span></span><br><span class="line"><span class="string">#Type THRESH_BINARY_INV   //    THRESH_BINARY</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 自适应阈值二值化 adaptiveThreshold(img,maxVal,adaptiveMethod,type,blockSize,C)</span></span><br><span class="line"><span class="string"># adaptiveMethod 计算邻进区域的平均值   //   高斯窗口加权平均值</span></span><br><span class="line"><span class="string"># Type     THRESH_BINARY_INV   //    THRESH_BINARY</span></span><br><span class="line"><span class="string">dst = cv2.adaptiveThreshold(kunkun2,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;math&#x27;,kunkun2)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;math2&#x27;,dst)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !腐蚀</span></span><br><span class="line"><span class="comment"># erode(img,kernel,iterations)  iterations执行的次数</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./j.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel_3 = np.ones((5,5),np.uint8)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">j2 = cv2.erode(j,kernel_3,iterations= 1)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获得卷积核</span></span><br><span class="line"><span class="comment"># getStructuringElement(type,size)</span></span><br><span class="line"><span class="comment"># type  -- MORPH_RECT(矩形，全1)   -- MORPH_ELLIPSE(椭圆)   --MORPH_CROSS(十字架)</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./j.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))</span></span><br><span class="line"><span class="string">j2 = cv2.erode(j,kernel,iterations= 1)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !膨胀</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># dilate(img, kernel, iterations=1)</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./j.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))</span></span><br><span class="line"><span class="string">j2 = cv2.erode(j,kernel,iterations= 1)</span></span><br><span class="line"><span class="string">j2= cv2.dilate(j2,kernel,iterations= 1)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#! 开运算</span></span><br><span class="line"><span class="comment"># MORPH_OPEN先腐蚀-&gt;再膨胀 = 开运算</span></span><br><span class="line"><span class="comment"># 消除黑底白色噪点</span></span><br><span class="line"><span class="comment"># morphologyEx(img, MORPH_OPEN, kernel)</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./hei.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(18,18))</span></span><br><span class="line"><span class="string">j2 = cv2.morphologyEx(j,cv2.MORPH_OPEN,kernel)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !闭运算</span></span><br><span class="line"><span class="comment"># MORPH_OPEN膨胀 -&gt; 腐蚀</span></span><br><span class="line"><span class="comment"># 白底黑色噪点</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./dotinj.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(8,8))</span></span><br><span class="line"><span class="string">j2 = cv2.morphologyEx(j,cv2.MORPH_CLOSE,kernel)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !形态学梯度</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 梯度 MORPH_GRADIENT= 原图 - 腐蚀</span></span><br><span class="line"><span class="comment"># 显示轮廓</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./J.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))</span></span><br><span class="line"><span class="string">j2 = cv2.morphologyEx(j,cv2.MORPH_GRADIENT,kernel)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># !顶帽运算</span></span><br><span class="line"><span class="comment"># 顶帽 （黑底白色噪点）= 原图 - 开运算 </span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./hei.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(19,19))</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">j2 = cv2.morphologyEx(j,cv2.MORPH_TOPHAT,kernel)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># !黑帽运算</span></span><br><span class="line"><span class="comment"># 黑帽（白底黑色噪点） = 原图 - 闭运算</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;j2&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string">j = cv2.imread(&#x27;./dotinj.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(9,9))</span></span><br><span class="line"><span class="string">j2 = cv2.morphologyEx(j,cv2.MORPH_BLACKHAT,kernel)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j&#x27;,j)</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;j2&#x27;,j2)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># *图像轮廓</span></span><br><span class="line"><span class="comment"># 具有相同颜色或强度的连续点的曲线</span></span><br><span class="line"><span class="comment"># 1.先对图像进行二值化，再进行Canny操作</span></span><br><span class="line"><span class="comment"># 2.画轮廓时会修改输入的图像</span></span><br><span class="line"><span class="comment"># 轮廓查找api</span></span><br><span class="line"><span class="comment">#     findContours(img,</span></span><br><span class="line"><span class="comment">#                   mode,   RETR_EXTERNAL = 0 -只检测外围轮廓  RETR_LIST = 1  -检测的轮廓不建立等级关系    RETR_CCOMP = 2 -每层最多两级  RETR_TREE -按树型存储轮廓</span></span><br><span class="line"><span class="comment">#                   ApproximationMode   CHAIN_APPROX_NONE -保存所有轮廓上的点    CHAIN_APPROX_SIMPLE -只保存角点    </span></span><br><span class="line"><span class="comment">#                  )  return  contours(查找到的所有轮廓)    hierarchy(轮廓之间有没有层级关系)</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string">def drawShape(src, points):</span></span><br><span class="line"><span class="string">    i = 0</span></span><br><span class="line"><span class="string">    while i &lt;len(points):</span></span><br><span class="line"><span class="string">        if(i == len(points)-1) :</span></span><br><span class="line"><span class="string">            x,y = points[i][0]</span></span><br><span class="line"><span class="string">            x1,y1 = points[0][0]</span></span><br><span class="line"><span class="string">            cv2.line(src,(x,y),(x1,y1),(0,255,0),1)</span></span><br><span class="line"><span class="string">        else :</span></span><br><span class="line"><span class="string">            x,y = points[i][0]</span></span><br><span class="line"><span class="string">            x1,y1 = points[i+1][0]</span></span><br><span class="line"><span class="string">            cv2.line(src,(x,y),(x1,y1),(0,255,0),1)   </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        i+=1</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 读文件</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_GUI_NORMAL)</span></span><br><span class="line"><span class="string">img = cv2.imread(&#x27;./123.png&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 转为灰度图</span></span><br><span class="line"><span class="string">img2 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 二值化</span></span><br><span class="line"><span class="string">ret,dst = cv2.threshold(img2,120,255,cv2.THRESH_BINARY)</span></span><br><span class="line"><span class="string"># ret,dst = cv2.threshold(kunkun2, 180, 255, cv2.THRESH_BINARY)</span></span><br><span class="line"><span class="string">#Type THRESH_BINARY_INV   //    THRESH_BINARY</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># !轮廓查找</span></span><br><span class="line"><span class="string">con,hie = cv2.findContours(dst,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># !轮廓绘制</span></span><br><span class="line"><span class="string"># drawContours(img, contours,     ---- 轮廓坐标点</span></span><br><span class="line"><span class="string">#                   contourIdx,   ---- 顺序          -1表示所有轮廓</span></span><br><span class="line"><span class="string">#                   color,        ---- 轮廓的颜色    </span></span><br><span class="line"><span class="string">#                   thickness ...) ----线宽</span></span><br><span class="line"><span class="string">cv2.drawContours(img,con,-1,(0,255,0),2)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># !计算轮廓的面积和周长</span></span><br><span class="line"><span class="string"># contourArea(contour)面积</span></span><br><span class="line"><span class="string"># contour :轮廓</span></span><br><span class="line"><span class="string"># arcLength(curve 轮廓, closed 是否闭合)周长</span></span><br><span class="line"><span class="string">area = cv2.contourArea(con[1])</span></span><br><span class="line"><span class="string">print()</span></span><br><span class="line"><span class="string">#! 多边形逼近与凸包</span></span><br><span class="line"><span class="string"># 逼近approxPolyDP(curve 轮廓, epsilon 精度, closed 是否闭合)</span></span><br><span class="line"><span class="string">#cv2.approxPolyDP()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 凸包convexHull(points 轮廓, clockwise True顺时针 逆时针)</span></span><br><span class="line"><span class="string"># point = cv2.approxPolyDP(con[0],10,closed= True)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 外界矩形 最小外接矩形  最大外界矩形</span></span><br><span class="line"><span class="string"># minAreaRect(points 轮廓)  return  中点坐标(x,y)   width,height   angle    最小外接矩形</span></span><br><span class="line"><span class="string"># maxAreaRect(array /points)      返回  Rect   --x,y   width,height</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">#drawShape(img,point)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># print()</span></span><br><span class="line"><span class="string">cv2.imshow(&#x27;new&#x27;,img)</span></span><br><span class="line"><span class="string">cv2.waitKey(0)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#//////////////////////*车辆统计</span></span><br><span class="line"></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">import cv2</span></span><br><span class="line"><span class="string">import numpy as np</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"># 窗口的展示</span></span><br><span class="line"><span class="string"># 基本图像的运算与处理</span></span><br><span class="line"><span class="string">#      -背景的去除cv2.createBackgroundSubtractorMOG()   history =200  </span></span><br><span class="line"><span class="string">#       </span></span><br><span class="line"><span class="string"># 形态学   --腐蚀，膨胀，开操作，闭操作，顶帽，黑帽</span></span><br><span class="line"><span class="string"># 轮廓查找</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">#*流程</span></span><br><span class="line"><span class="string"># 加载视频</span></span><br><span class="line"><span class="string"># 通过形态学识别车辆</span></span><br><span class="line"><span class="string"># 轮廓查找</span></span><br><span class="line"><span class="string"># 统计</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">#*创建窗口</span></span><br><span class="line"><span class="string">cv2.namedWindow(&#x27;new&#x27;,cv2.WINDOW_NORMAL)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">bgsumog = cv2.createBackgroundSubtractorMOG2(history= 500)</span></span><br><span class="line"><span class="string">#a = cv2.createBackgroundSubtractorKNN(history= 200)</span></span><br><span class="line"><span class="string">#* 加载视频</span></span><br><span class="line"><span class="string">cap = cv2.VideoCapture(&#x27;./video.mp4&#x27;)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">def center(x,y,w,h):</span></span><br><span class="line"><span class="string">    x1 = int(x + w/2)</span></span><br><span class="line"><span class="string">    y1 = int(y + h/2)</span></span><br><span class="line"><span class="string">    return (x1,y1)</span></span><br><span class="line"><span class="string">#*获得卷积核</span></span><br><span class="line"><span class="string">kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))  #获得卷积核</span></span><br><span class="line"><span class="string">kernel2 = cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))  #获得卷积核</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">while True:</span></span><br><span class="line"><span class="string">    ret,frame =cap.read()</span></span><br><span class="line"><span class="string">    if ret == True:</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*灰度化</span></span><br><span class="line"><span class="string">        frame_gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*高斯去噪</span></span><br><span class="line"><span class="string">        frame_blur = cv2.GaussianBlur(frame_gray,(5,5),sigmaX=5)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*去背景</span></span><br><span class="line"><span class="string">        frame_mask = bgsumog.apply(frame_blur)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*二值化</span></span><br><span class="line"><span class="string">        ret,frame_mask = cv2.threshold(frame_mask, 150, 255, cv2.THRESH_BINARY)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*腐蚀</span></span><br><span class="line"><span class="string">        frame_erode = cv2.erode(frame_mask,kernel,iterations=2)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*膨胀  </span></span><br><span class="line"><span class="string">        </span></span><br><span class="line"><span class="string">        frame_dilate =  cv2.dilate(frame_erode,kernel,iterations=3)</span></span><br><span class="line"><span class="string">        </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #*闭操作</span></span><br><span class="line"><span class="string">        frame_closeAction = cv2.morphologyEx(frame_dilate, cv2.MORPH_OPEN, kernel)</span></span><br><span class="line"><span class="string">        frame_closeAction = cv2.morphologyEx(frame_closeAction, cv2.MORPH_OPEN, kernel)</span></span><br><span class="line"><span class="string">        #frame_closeAction = cv2.morphologyEx(frame_closeAction, cv2.MORPH_OPEN, kernel)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        frame_erode_2 = cv2.erode(frame_closeAction,kernel)</span></span><br><span class="line"><span class="string">        # frame_dilate_2 =  cv2.dilate(frame_erode_2,kernel)</span></span><br><span class="line"><span class="string">        # frame_closeAction_2 = cv2.morphologyEx(frame_erode_2, cv2.MORPH_OPEN, kernel2)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        #* 查找轮廓</span></span><br><span class="line"><span class="string">        frame_con,hie = cv2.findContours(frame_closeAction,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)</span></span><br><span class="line"><span class="string">        for(i,c)  in enumerate(frame_con):</span></span><br><span class="line"><span class="string">            (x,y,w,h)= cv2.boundingRect(c)</span></span><br><span class="line"><span class="string">            if (w&gt;=50 and h&gt;=80):</span></span><br><span class="line"><span class="string">                cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">                #*算中心点</span></span><br><span class="line"><span class="string">                cy = center(x,y,w,h)</span></span><br><span class="line"><span class="string">                cv2.circle(frame,cy,5,(0,255,0),-1)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        cv2.imshow(&#x27;new&#x27;,frame)</span></span><br><span class="line"><span class="string">        </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    if cv2.waitKey(50) &amp; 0xff==27:</span></span><br><span class="line"><span class="string">        break</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">cap.release()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">cv2.destroyAllWindows()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">戎老大</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2023/03/22/opencv/">http://example.com/2023/03/22/opencv/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">一个不知道名字的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/rong_blog_cover.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/04/06/%E5%9F%BA%E4%BA%8Eesp32%E7%9A%84ws2812%E7%82%B9%E9%98%B5rgb%E5%B1%8F%E5%B9%95%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE/" title="基于esp32的ws2812点阵rgb屏幕开源项目"><img class="cover" src="/img/rong_blog_cover.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">基于esp32的ws2812点阵rgb屏幕开源项目</div></div></a></div><div class="next-post pull-right"><a href="/2023/03/11/%E5%85%B3%E4%BA%8EFreeRTOS%E7%9A%84%E9%98%9F%E5%88%97%E7%9A%84%E7%AC%94%E8%AE%B0/" title="关于FreeRTOS的队列的笔记"><img class="cover" src="/img/rong_blog_cover.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">关于FreeRTOS的队列的笔记</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://rong-1315651883.cos.ap-beijing.myqcloud.com/rong-1315651883/dog.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">戎老大</div><div class="author-info__description">hi，别来无恙啊</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/rongtopman"><i class="fab fa-gitee"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/rongtopman" target="_blank" title="Gitee"><i class="fab fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><b><font color="#e66b6d">欢</font> <font color="#e66d98">迎</font> <font color="#e66cc6">来</font> <font color="#cc6de6">到</font> <font color="#9770e6">我</font> <font color="#6d93e6">的</font> <font color="#6fcde6">博</font> <font color="#72e6b6">客</font> <p align="center"><img src="https://img-blog.csdnimg.cn/f7384c88956d4378b72e47548e19c9f8.gif" width="50" alt="mao"></p> <p align="center">微信号：R2740931764</p> <p align="center">QQ号：2740931764</p></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#opencv%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B8%8A%E4%BC%A0"><span class="toc-number">1.</span> <span class="toc-text">opencv学习笔记上传</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/04/16/PyQT%E7%AC%94%E8%AE%B0/" title="python面向对象案例之PyQT(一)"><img src="/img/rong_blog_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python面向对象案例之PyQT(一)"/></a><div class="content"><a class="title" href="/2023/04/16/PyQT%E7%AC%94%E8%AE%B0/" title="python面向对象案例之PyQT(一)">python面向对象案例之PyQT(一)</a><time datetime="2023-04-16T06:50:25.000Z" title="发表于 2023-04-16 14:50:25">2023-04-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/04/10/C%E8%AF%AD%E8%A8%80%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" title="C语言内存管理"><img src="/img/rong_blog_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C语言内存管理"/></a><div class="content"><a class="title" href="/2023/04/10/C%E8%AF%AD%E8%A8%80%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" title="C语言内存管理">C语言内存管理</a><time datetime="2023-04-10T14:34:03.000Z" title="发表于 2023-04-10 22:34:03">2023-04-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/04/08/python-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" title="python 面向对象"><img src="/img/rong_blog_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python 面向对象"/></a><div class="content"><a class="title" href="/2023/04/08/python-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" title="python 面向对象">python 面向对象</a><time datetime="2023-04-07T19:02:27.000Z" title="发表于 2023-04-08 03:02:27">2023-04-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/04/07/%E5%9F%BA%E4%BA%8Epython%E7%9A%84%E4%B8%B2%E5%8F%A3%E7%AC%94%E8%AE%B0/" title="基于python的串口通信"><img src="/img/rong_blog_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="基于python的串口通信"/></a><div class="content"><a class="title" href="/2023/04/07/%E5%9F%BA%E4%BA%8Epython%E7%9A%84%E4%B8%B2%E5%8F%A3%E7%AC%94%E8%AE%B0/" title="基于python的串口通信">基于python的串口通信</a><time datetime="2023-04-07T04:19:52.000Z" title="发表于 2023-04-07 12:19:52">2023-04-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/04/06/%E5%9F%BA%E4%BA%8Eesp32%E7%9A%84ws2812%E7%82%B9%E9%98%B5rgb%E5%B1%8F%E5%B9%95%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE/" title="基于esp32的ws2812点阵rgb屏幕开源项目"><img src="/img/rong_blog_cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="基于esp32的ws2812点阵rgb屏幕开源项目"/></a><div class="content"><a class="title" href="/2023/04/06/%E5%9F%BA%E4%BA%8Eesp32%E7%9A%84ws2812%E7%82%B9%E9%98%B5rgb%E5%B1%8F%E5%B9%95%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE/" title="基于esp32的ws2812点阵rgb屏幕开源项目">基于esp32的ws2812点阵rgb屏幕开源项目</a><time datetime="2023-04-06T06:18:28.000Z" title="发表于 2023-04-06 14:18:28">2023-04-06</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/rong_blog_cover.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 戎老大</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: 'https://twikoo.rongtopman.icu',
      region: '',
      onCommentLoaded: function () {
        btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
      }
    }, null))
  }

  const getCount = () => {
    const countELement = document.getElementById('twikoo-count')
    if(!countELement) return
    twikoo.getCommentsCount({
      envId: 'https://twikoo.rongtopman.icu',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      countELement.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const runFn = () => {
    init()
    
  }

  const loadTwikoo = () => {
    if (typeof twikoo === 'object') {
      setTimeout(runFn,0)
      return
    } 
    getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js').then(runFn)
  }

  if ('Twikoo' === 'Twikoo' || !false) {
    if (false) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo()
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script></div><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/hsu_package/card-music/aplayer_cus.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div class="hide" id="card-music"><div id="card-wrapper"></div><div id="card-front"><meting-js id="7841201322" server="netease" type="playlist" mutex="true" preload="none" theme="var(--hsu-theme-color)" data-lrctype="0" order="random" list-folded="true"></meting-js></div><div id="card-back"><div id="button-music"><i class="fa-solid fa-music"></i></div></div></div><div class="hide" id="music-close-button"><i class="fa-solid fa-music"></i></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: 'https://twikoo.rongtopman.icu',
      region: '',
      onCommentLoaded: function () {
        btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
      }
    }, null))
  }

  const getCount = () => {
    const countELement = document.getElementById('twikoo-count')
    if(!countELement) return
    twikoo.getCommentsCount({
      envId: 'https://twikoo.rongtopman.icu',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      countELement.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const runFn = () => {
    init()
    
  }

  const loadTwikoo = () => {
    if (typeof twikoo === 'object') {
      setTimeout(runFn,0)
      return
    } 
    getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js').then(runFn)
  }

  if ('Twikoo' === 'Twikoo' || !false) {
    if (false) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo()
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script></div><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/hsu_package/card-music/aplayer_cus.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://beian.miit.gov.cn/#/Integrated/index" style="margin-inline:5px" data-title="本站已在晋ICP备2023000074号进行备案" title=""><img src="https://img.shields.io/badge/本站已在晋ICP备2023000074号进行备案-e1d492?style=flat&amp;logo=" alt=""/></a></p>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="https://unpkg.zhimg.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.min.js"></script><!-- hexo injector body_end end --></body></html>